package activity.study.initmysql;

import de.odysseus.el.TreeValueExpression;
import org.activiti.engine.impl.delegate.invocation.DefaultDelegateInterceptor;
import org.activiti.engine.impl.delegate.invocation.DelegateInvocation;

import java.lang.reflect.Field;

public class HcDefaultDelegateInterceptor extends DefaultDelegateInterceptor {


    @Override
    public void handleInvocation(DelegateInvocation invocation) {
        System.out.println("HcDefaultDelegateInterceptor.handleInvocation, 获取表达式：" + ((TreeValueExpression)invocation.getTarget()).getExpressionString());
//        super.handleInvocation(invocation);


        final Class<DelegateInvocation> delegateInvocationClass = DelegateInvocation.class;
        try {
            // TODO 已经成功获取了表达式，这里只需要解析表达式就行了，这里写业务逻辑判断条件的true和false，然后暴力访问设置到invocationResult中
            final Field invocationResult = delegateInvocationClass.getDeclaredField("invocationResult");
            invocationResult.setAccessible(true);
            invocationResult.set(invocation, false);
//            invocationResult.set(invocation, true);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
